Originally Posted by
ghoul
No it is not. Pointer arithmetic is syntactic sugar .
syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express.
What are you saying it is 'syntactic sugar' for? Array indexing?
I would argue the other way around - that arrays are sugar for pointer arithmetic + dereferencing...
...except arrays and pointers are subtilty different.
If you can successfully predict the output of this code without running it, then you know what I mean.
Code:
#include <stdio.h>
void func(char buffer[1000], char *ptr)
{
printf("In func() sizeof(buffer) is %zi\n", sizeof(buffer));
printf("In func() sizeof(ptr) is %zi\n", sizeof(ptr));
}
int main(void)
{
char buffer[1000];
char *ptr;
ptr = buffer;
printf("In main() sizeof(buffer) is %zi\n", sizeof(buffer));
printf("In main() sizeof(ptr) is %zi\n", sizeof(ptr));
func(buffer, ptr);
return 0;
}
Go on... give it a try. What will the question marks be?
Code:
In main() sizeof(buffer) is ?
In main() sizeof(ptr) is ?
In func() sizeof(buffer) is ?
In func() sizeof(ptr) is ?
it can't be pure sugar if it tastes differently (pointers and arrays, that is).
It's why it is said "arrays decay to pointers" not "arrays are pointers".